package com.example.whopxx;

import com.example.whopxx.dao.UserDao;
import com.example.whopxx.domain.User;
import com.example.whopxx.domain.UserBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "IndexServlet", value = "/IndexServlet")
public class IndexServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        System.out.println(user);
        if (user != null){
            UserDao userDao = new UserDao();

            List<UserBean> list = userDao.findAll();
            request.setAttribute("list", list);
            request.getRequestDispatcher("manager.jsp").forward(request, response);
//            response.sendRedirect("manager.jsp")
        }
        else {
            response.sendRedirect("login.jsp");
        }
    }
}
